package cn.ai.shoes.client.config;

import cn.ai.shoes.client.api.ComfyuiApi;
import cn.ai.shoes.client.entity.CurrentServerEntity;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

import java.util.concurrent.TimeUnit;

@Configuration
@Slf4j
public class ComfyuiConfig {

    /**
     * 配置OkHttpClient（含日志/重试/超时）
     * @return
     */
    @Bean
    public OkHttpClient okHttpClient() {
        // 创建HTTP日志拦截器实例
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        // 添加网络请求日志功能
        // 自动重试失败连接（提升网络可靠性）
        // 设置30秒连接超时（防止长时间阻塞）
        return new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .retryOnConnectionFailure(true)
                .connectTimeout(30, TimeUnit.SECONDS)
                .build();
    }

}
